<?php

class Thoitiet{
	var $ID ="";
	var $Date="";
	var $City="";
	var $Temperature="";
	var $Desc="";
	var $Status="";
	function Thoitiet() { // Constructor
	}
	function Add() {
		
			$sql = "INSERT INTO thoitiet  (`Date`,`City`,`Temperature`,`Desc`)";
			$sql .= " VALUES ('$this->Date','$this->City','$this->Temperature','$this->Desc')";
			$sqlObj = new SQLHandler($sql);
			if($sqlObj->ExecuteUpdate())
				return true;
			else
				return false;
	}
	function Edit() {
		$sql = "UPDATE thoitiet  SET `Date`='$this->Date', `City`='$this->City',";
		$sql .= "`Temperature`='$this->Temperature',`Desc`='$this->Desc'";
		$sql .= " WHERE ID='".$this->ID."'";
		$sqlObj = new SQLHandler($sql);
		if($sqlObj->ExecuteUpdate())
			return true;
		else
			return false;
	}
		function ChangeStatus() {
		$sql = "UPDATE thoitiet  SET `Status`=NOT(`Status`) ";
		$sql .= " WHERE ID='".$this->ID."'";
		$sqlObj = new SQLHandler($sql);
		if($sqlObj->ExecuteUpdate())
			return true;
		else
			return false;
	}
	function Update() {
		$sql = "UPDATE thoitiet  SET `Date`='$this->Date', `City`='$this->City',";
		$sql .= "`Temperature`='$this->Temperature',`Desc`='$this->Desc'";
		$sql .= " WHERE City='".$this->City."' AND Date='".$this->Date."'";
		$sqlObj = new SQLHandler($sql);
		if($sqlObj->ExecuteUpdate())
			return true;
		else
			return false;
	
	}
	function Remove() {
		$sql = "DELETE FROM thoitiet  WHERE ID='".$this->ID."'";
		$sqlObj = new SQLHandler($sql);
		if($sqlObj->ExecuteUpdate())
			return true;
		else
			return false;
	}
	function GetAll($OrderBy) {
		if($OrderBy == "")
			$OrderBy = "ORDER BY ID DESC";
		$sql = "SELECT * FROM thoitiet  ".$OrderBy;
		$sqlObj = new SQLHandler($sql);
		return $array = $sqlObj->ExecuteQuery();
	}
	function GetAllPaged($offset, $limit) {
		$sql = "SELECT * FROM thoitiet  LIMIT $offset, $limit";
		$sqlObj = new SQLHandler($sql);
		return $array = $sqlObj->ExecuteQuery();
	}
	function GetById($Id) {
		$sql = "SELECT * FROM thoitiet  WHERE ID='".$Id."'";
		$sqlObj = new SQLHandler($sql);
		$row = $sqlObj->ExecuteQuery();
		$this->ID=$Id;
		$this->Date = $row[0]['Date'];
		$this->City    = $row[0]['City'];
		$this->Temperature    = $row[0]['Temperature'];
		$this->Desc     = $row[0]['Desc'];
		return $this;
	}	
	function GetByDate($Date) {
		$sql = "SELECT * FROM thoitiet  WHERE Date='".$Date."'";
		$sqlObj = new SQLHandler($sql);
		return $array = $sqlObj->ExecuteQuery();
	}	
}
?>